import React, { useEffect, useState } from 'react';
import TableHeader from '@/components/TableHeader/TableHeader';
import { useDispatch, useSelector } from "umi";
import SearchContainer from '@/components/SearchContainer/SearchContainer';
import DrawerDetail from '@/components/Drawer/Drawer';
import Dialog from '@/components/Dialog/Dialog';
import TableLists from "./components/TableLists";
import SearchForm from "@/components/CommonSearchForm"
import RewAndPubDetail from "./components/RewAndPubDetail"
import AddRewAndPub from "./components/AddRewAndPub";
import { setIsShowAdd } from '@/utils/commonFns/commonDispatch';

export default function index() {
    const dispatch = useDispatch();
    const { rewAndPubLists, rewAndPubTotal, rewAndPubDetail, rewAndPubSearch } = useSelector(state => state.rewardAndPunishment);//搜索内容 总数 数据
    const { isShowAdd } = useSelector(state => state.common);
    const { page, size, queryData } = rewAndPubSearch;
    const [closeRight, setcloseRight] = useState(false);
    useEffect(() => {
        _initContentPage();
    }, []);

    // 初始化数据,修改页码
    function _initContentPage(page = 1, queryData = {}) {
        if (typeof queryData !== 'object') {
            queryData = {};
        }
        dispatch({
            type: "rewardAndPunishment/initRewAndPubContent",
            payload: { page, queryData }
        })
    }

    function reload(queryData) {
        console.log(queryData)
        _initContentPage(1, queryData)
    }

    function addStaffFn() {
        setIsShowAdd(false, dispatch);
        changeDiallogValue();
    }

    return (
        <div className='main-content'>
            {/* 头部定位按钮 */}
            <TableHeader
                total={rewAndPubTotal}
                page={page}
                size={size}
                interfaceDelMethod={"deleteRewardAndPunishment"}
                changeCurrentPage={_initContentPage}
                getNewDatas={() => _initContentPage()}
                openAdd={() => setIsShowAdd(true, dispatch)}
            ></TableHeader>
            {/* 搜索内容 */}
            <SearchContainer
                renderForm={() => <SearchForm reload={reload}></SearchForm>}
                closeRight={closeRight}
                setcloseRight={setcloseRight}></SearchContainer>
            {/* 表格显示 */}
            <TableLists data={rewAndPubLists} changeDiallogValue={_initContentPage}></TableLists>
            {/* 详情展示 */}
            <DrawerDetail
                title={rewAndPubDetail?.staffName?.userName}
                _id={rewAndPubDetail?._id}
                render={() => <RewAndPubDetail rewAndPubDetail={rewAndPubDetail} _initrewAndPubList={_initContentPage}></RewAndPubDetail>}
                reloadFunc={_initContentPage}
                interfaced={"deleteRewardAndPunishment"}
                isStaff={true}
            >
            </DrawerDetail>
            {/* 新增展示 */}
            <Dialog
                isShowClose={true}
                title={"新增职级"}
                width={800}
                dialogStutus={isShowAdd}
                setDialogStatus={(type) => setIsShowAdd(type, dispatch)}
                render={() => <AddRewAndPub
                    addStaffFn={addStaffFn}></AddRewAndPub>}></Dialog>

        </div>
    )
}
